home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
001-100
/
001-025
/
002
/
cc
/
sprintfbug.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-17
|
1KB
|
36 lines
/*
* This program demonstrates that there is a limitation on how long
* a string "sprintf()" is capable of printing. On my machine, it
* appears to be 200 characters. I don't know whether this is the
* limit on an individual argument, or the total of the argument
* lengths, but it would be easy enough to write another test program
* to find out. So, beware..., this has already bitten me once.
*
* Also, note that when the limit is reached, sprintf returns a value
* one greater than the actual number of characters placed in the
* output buffer.
*
* Fred Fish
*/
#include <stdio.h>
#define MAXSIZE (256)
main ()
{
auto char buffer1[MAXSIZE+1];
auto char buffer2[MAXSIZE+1];
register int index;
register int xfered;
buffer1[0] = 0;
buffer2[0] = 0;
for (index=0; index < MAXSIZE; index++) {
xfered = sprintf (buffer1, "%s%c", buffer2, '0' + (index % 10));
printf ("%3.3d: %s\n", xfered, buffer1);
fflush (stdout);
strcpy (buffer2, buffer1);
}
}